package controllers;

import java.util.List;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.Page;
import com.avaje.ebean.PagingList;
import com.fasterxml.jackson.databind.node.ObjectNode;

import models.monitor.ScheduleETL;
import play.mvc.*;
import play.libs.Json;


public class Application extends Controller {

    public static Result index() {
        return ok(views.html.index.render("AAA"));
    }
    
    @BodyParser.Of(BodyParser.Json.class)
    public static Result json() {
    	//List<ScheduleETL> list = ScheduleETL.find.all();
    	
    	 PagingList<ScheduleETL> pagingList = Ebean.find(ScheduleETL.class)
         .findPagingList(10);
    	
    	 Page<ScheduleETL> page0 = pagingList.getPage(0);
         List<ScheduleETL> list = page0.getList();
         
    	ObjectNode dataJson = Json.newObject();
    	dataJson.put("total", pagingList.getTotalRowCount());
    	dataJson.put("list", Json.toJson(list));
    	
    	//Ebean.createSqlQuery(sql)
    	
        return ok(dataJson);
    }
    
    public static void main(String[] args){
    	
    	String target = "2014/01/25";
    	
    	System.out.println("Date: " + Integer.parseInt(target.replace("/", "")));
    }
}
